use std::{fs, io, thread, time::Duration};
use std::fs::ReadDir;

pub fn get_directory() -> (ReadDir, String) {
    println!("请输入你需要处理的文件夹,直接enter回车为当前文件夹");
    let mut dir = String::new();
    io::stdin().read_line(&mut dir).unwrap();
    let dir_trim = dir.trim().to_string();
    let (dirs,dir_s )= match fs::read_dir(&dir_trim) {
        Ok(dirs) => {
            match &dir_trim.len() {
                0 => println!("你输入的文件夹为空,使用当前文件夹"),
                _ => println!("你输入的文件夹为:{}", &dir_trim)
            }
            (dirs,dir_trim)
        }
        _ => {
            println!("你输入的文件夹不存在,请重新输入");
            thread::sleep(Duration::from_millis(1000));
            println!("-----------------------");
            let (dir_t, dir_trim_t) = get_directory();
            (dir_t,dir_trim_t)
        }
    };
    (dirs, dir_s)
}
